<template>
  <a-modal :width="1000" v-model:visible="visible" :unmount-on-close="true">
    <a-card :title="info.name" class="padding" v-if="visible">
      <template #extra>
      </template>
      <div class="flex justify-between">
        <div>
          余额:{{ info.money.money }}元
          <!-- <a-button @click="addMoneyRef.open(info, () => {
              load()
          })">充值</a-button> -->
        </div>
        <div>
          本月消费金额：{{ info.money.this_month_money_sum }}元
        </div>
        <div>
          累计消费金额：{{ info.money.all_money_sum }}元
        </div>
        <div>
          周期结算待结款：{{ info.money.outstanding_money_sum }}元
        </div>
      </div>

      <div class="mt-5">
        周期结算账单日:
        <a-input-number style="width: 4em;" @change="bill_day_edit_fun" :min="1" :max="30" v-if="bill_day_edit" v-model="info.money.bill_day"/>
        <span v-else>
          {{ info.money.bill_day }}
        </span>
        号
        <a-button @click="bill_day_edit = true">修改</a-button>
      </div>
      <div>
        每月X号生成周期账单。例如，账单日设置的1日，则每月1号生成上月业务产生的账单。
      </div>

      <div class="mt-5">
        周期账单结算日:
        <a-input-number style="width: 4em;" @change="settle_day_edit_fun" :min="1" :max="30" v-if="settle_day_edit" v-model="info.money.settle_day"/>
        <span v-else>
          {{ info.money.settle_day }}
        </span>
        号
        <a-button @click="settle_day_edit = true">修改</a-button>
      </div>

      <div>
        每月X号结算上一个月的周期账单，若是客户超期未结算周期账单，则禁止提货。例如，结算日设置的5号，则每月5号之前完成账单结算，若是未完成结算将不能继续提货。
      </div>
    </a-card>
  </a-modal>
  <AddMoneyModal
      ref="addMoneyRef"
  />
</template>

<script setup>

import {ref} from "vue";
import dept from "@/api/system/dept";
import FinancialTopDeptMoney from "@/api/financial/financialTopDeptMoney";
import {Message} from "@arco-design/web-vue";
import AddMoneyModal from "@/views/financial/moneyLog/AddMoney.vue"

const addMoneyRef = ref()
const visible = ref(false)
const info = ref({})
const settle_day_edit = ref(false)
const bill_day_edit = ref(false)

const settle_day_edit_fun = async () => {
  settle_day_edit.value = false
  let res = await FinancialTopDeptMoney.update(info.value.money.id,{
    settle_day: info.value.money.settle_day
  })
  if (res.success) {
    Message.success(res.message)
  }
}

const bill_day_edit_fun = async () => {
  bill_day_edit.value = false
  let res = await FinancialTopDeptMoney.update(info.value.money.id,{
    bill_day: info.value.money.bill_day
  })
  if (res.success) {
    Message.success(res.message)
  }
}

var load = null

defineExpose({
  async open(id){
    load = async () => {
      settle_day_edit.value = false
      bill_day_edit.value = false
      let res = await dept.read({
        id: id,
      })
      info.value = res.data
      visible.value = true
    }
    load()
  }
})
</script>

<style scoped>

</style>
